<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->theme->baseUrl; ?>/frontend/js/bootstrap.min.js"></script>

<script type="text/javascript" src='<?php echo Yii::app()->theme->baseUrl; ?>/frontend/js/jquery.heapbox-0.9.2.js'></script>
<link rel="stylesheet" href="<?php echo Yii::app()->theme->baseUrl; ?>/frontend/css/horizontal.css">
<link rel="stylesheet" href="<?php echo Yii::app()->theme->baseUrl; ?>/frontend/css/scrollbar.css">

<script type="text/javascript" src='<?php echo Yii::app()->theme->baseUrl; ?>/frontend/js/jquery.mousewheel.min.js'></script>
<script type="text/javascript" src='<?php echo Yii::app()->theme->baseUrl; ?>/frontend/js/jquery.touchSwipe.min.js'></script>
<script type="text/javascript" src='<?php echo Yii::app()->theme->baseUrl; ?>/frontend/js/jquery.transit.min.js'></script>
<script type="text/javascript" src='<?php echo Yii::app()->theme->baseUrl; ?>/frontend/js/jquery.easing.1.3.js'></script>
<script type="text/javascript" src='<?php echo Yii::app()->theme->baseUrl; ?>/frontend/js/jquery.slides.min.js'></script>
<script type="text/javascript" src='<?php echo Yii::app()->theme->baseUrl; ?>/frontend/js/horizontal.js'></script>
<script type="text/javascript" src="<?php echo Yii::app()->theme->baseUrl; ?>/frontend/js/jquery.nicescroll.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&language=vi"></script>
<script src="<?php echo Yii::app()->theme->baseUrl; ?>/frontend/js/jquery-ui-1.10.4.custom.min.js"></script>
<?php $link = MyFunctionCustom::getFacebookLoginUrlTest(); ?>
<script type="text/javascript">
    var newwindow;
    var intId;
    function login() {
        $('#Modal-login').modal('hide');
        var screenX = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft,
                screenY = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop,
                outerWidth = typeof window.outerWidth != 'undefined' ? window.outerWidth : document.body.clientWidth,
                outerHeight = typeof window.outerHeight != 'undefined' ? window.outerHeight : (document.body.clientHeight - 22),
                width = 500,
                height = 270,
                left = parseInt(screenX + ((outerWidth - width) / 2), 10),
                top = parseInt(screenY + ((outerHeight - height) / 2.5), 10),
                features = (
                        'width=' + width +
                        ',height=' + height +
                        ',left=' + left +
                        ',top=' + top
                        );

        newwindow = window.open('<?php echo $link ?>', 'Login_by_facebook', features);

        if (window.focus) {
            newwindow.focus();
        }
        // parent.$.fancybox.close();
        return false;
    }
    $(document).ready(function() {

       
        $('.custom_select').heapbox('disable');
        // Using custom configuration
        // Get window width

        var ww = $(document).width();
        var widthOfwindow = JSON.parse(ww);
        // console.log(widthOfwindow);
        //Verify with screen width > 768
        if (ww > 768) {

            // console.log(ww);
            pfHeight = 652;
            wHeight = null;
            wHeight = $(window).height();

        } else {
            // alert($(window).height());
            $('.search').click(function() {
                $('.search_wrap').show();
                $('#dim-block').show();
            });
            $('#dim-block').click(function() {
                $('.search_wrap').hide();
                $('#dim-block').hide();
            });
        }
        return false;

    });
</script>

<script type="text/javascript">
    function number_format(number, decimals, dec_point, thousands_sep) {
        // From: http://phpjs.org/functions
        // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
        // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
        // +     bugfix by: Michael White (http://getsprink.com)
        // +     bugfix by: Benjamin Lupton
        // +     bugfix by: Allan Jensen (http://www.winternet.no)
        // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
        // +     bugfix by: Howard Yeend
        // +    revised by: Luke Smith (http://lucassmith.name)
        // +     bugfix by: Diogo Resende
        // +     bugfix by: Rival
        // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
        // +   improved by: davook
        // +   improved by: Brett Zamir (http://brett-zamir.me)
        // +      input by: Jay Klehr
        // +   improved by: Brett Zamir (http://brett-zamir.me)
        // +      input by: Amir Habibi (http://www.residence-mixte.com/)
        // +     bugfix by: Brett Zamir (http://brett-zamir.me)
        // +   improved by: Theriault
        // +      input by: Amirouche
        // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
        // *     example 1: number_format(1234.56);
        // *     returns 1: '1,235'
        // *     example 2: number_format(1234.56, 2, ',', ' ');
        // *     returns 2: '1 234,56'
        // *     example 3: number_format(1234.5678, 2, '.', '');
        // *     returns 3: '1234.57'
        // *     example 4: number_format(67, 2, ',', '.');
        // *     returns 4: '67,00'
        // *     example 5: number_format(1000);
        // *     returns 5: '1,000'
        // *     example 6: number_format(67.311, 2);
        // *     returns 6: '67.31'
        // *     example 7: number_format(1000.55, 1);
        // *     returns 7: '1,000.6'
        // *     example 8: number_format(67000, 5, ',', '.');
        // *     returns 8: '67.000,00000'
        // *     example 9: number_format(0.9, 0);
        // *     returns 9: '1'
        // *    example 10: number_format('1.20', 2);
        // *    returns 10: '1.20'
        // *    example 11: number_format('1.20', 4);
        // *    returns 11: '1.2000'
        // *    example 12: number_format('1.2000', 3);
        // *    returns 12: '1.200'
        // *    example 13: number_format('1 000,50', 2, '.', ' ');
        // *    returns 13: '100 050.00'
        // Strip all characters but numerical ones.
        number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
        var n = !isFinite(+number) ? 0 : +number,
                prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
                sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
                dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
                s = '',
                toFixedFix = function(n, prec) {
                    var k = Math.pow(10, prec);
                    return '' + Math.round(n * k) / k;
                };
        // Fix for IE parseFloat(0.55).toFixed(0) = 0;
        s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
        if (s[0].length > 3) {
            s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
        }
        if ((s[1] || '').length < prec) {
            s[1] = s[1] || '';
            s[1] += new Array(prec - s[1].length + 1).join('0');
        }
        return s.join(dec);
    }
</script>

<script type="text/javascript">

    (function(d, s, id) {
        var lang = <?php echo CJSON::encode(Yii::app()->session['_lang']); ?>;

        var lang_facebook;
        if (lang == 'vi') {
            lang_facebook = 'vi_VN';
        }
        else {
            lang_facebook = 'en_EN';
        }
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id))
            return;
        js = d.createElement(s);
        js.id = id;
        js.src = "//connect.facebook.net/" + lang_facebook + "/all.js#xfbml=1&appId=604540132949248";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
    function showfancy($that) {

        var href = $that.attr('ref');
        var classlogin = $that.attr('login');
        if (classlogin == 'details') {
            $.fancybox({
                'type': 'ajax',
                'href': href,
                autoSize: false,
                beforeShow: function() {
                    $(".fancybox-inner").addClass("details-popup");
                    // $(this).closeBtn.hide();
                    $(".fancybox-skin a.fancybox-item").addClass("details-close");
                    $('html').addClass('fancybox-lock');
                },
                afterShow: function() {
                    // var height = $(window).height();
                    // var width = $(window).width();
                    // if (width >= 1024) {
                    //   var add_height = height -25;
                    // }else{
                    //   var add_height = height -3;
                    // }
                    // if (width == 768) {
                    //   $('.details-popup').attr('style', 'width:' + (width - 5) + 'px !important;margin-left:0 !important;');
                    // }
                    // $('.details-popup').attr('style', 'height:' + add_height + 'px !important');
                    // $(".fancybox-inner").addClass("map-google");

                    $process_click = 0;
                    setTimeout(function() {
                        if (typeof (FB) !== 'undefined') {
                            FB.XFBML.parse();
                        }

                    }, 2000);

                },
                afterClose: function() {
                    //$('.nicescroll-rails').hide();
                },
                padding: 0
            });
        }
    }
    //function fancybox(){
    //    $process_click=0;
    //    $('.animation > .showfancy').swipe( {
    //          click:function(event, target)
    //        {
    //            $that=$(this);
    //            window.reloadfancy=function(){
    //                $('.fancybox-overlay').remove();
    //                showfancy($that);
    //                if (typeof(newwindow)!=='undefined') {
    //                       newwindow.close();
    //                    }
    //
    //
    //            };
    //            window.reloadfancy();
    //              return false;
    //            },
    //             fingers:'all',
    //        pinchThreshold:0 ,allowPageScroll: "vertical"});
    //}
    function viewdetail() {
        $('.show-event-ajax').swipe({click: function(event) {
                $this = $(this);
                showdetail($this);
                return false;
            }});
    }
    function showdetail($this) {
        showmodal($this);
        window.reloadfancy = function() {
            showmodal($this);
            if (typeof (newwindow) !== 'undefined') {
                newwindow.close();
            }
        }
    }
 
    function booked() {
        $('.choose-seat').click(function(){
            var seat = [];
                        $('.close-seatmap').click(function () {
                            // var text;
                      
//                            $('.text-seat').each(function(i){
//                                text = $(this).val();
//                                seat[$(this).attr('name')] = text;
////                     seat[i] = text.split(',');
//                                console.log(seat);
//                            });

                            $('#Modalseatmap').modal('hide');
                            return false;
                        });
                        $('#Modalseatmap').on('shown.bs.modal', function () {

                            setTimeout(function () {
                                $('.seatmap-nice-scroll').height($(window).height() - 100);
                                <?php
                                if (!preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"])) {
                                  echo ' $(\'.seatmap-nice-scroll\').jScrollPane();';
                                }
                                ?>
                            }, 500);
                        });
        });
        $('.ajax-submit-btn').bind('click', function() {
            $('.booked-modal').addClass('ajax-loading-block');
            $request.ajaxSubmit($(this), function(html) {
                // $('.booked-modal .modal-header').append(text);
                $('#Modal-book .modal-body').html(html);
                                {
                    total = 0;
                    $('.ticket-type').each (function () {
                        if($(this).is(":checked")){
                            price = $(this).attr('data-price');
                            quantity = $(this).parent().parent().find(".select-ticket-number").get(0).value;

                            total += price*quantity;
                        }
                    })

                    $('.total_price_num').html(number_format(total) + " VND");
                }

                $('.select-ticket-number').change(getTotalPrice);
                $('.ticket-type').change(getTotalPrice);
                $('.booked-modal').removeClass('ajax-loading-block');
                setTimeout(function() {
                    booked();
                }, 200);

            });
            return false;
        });

        // $(".table").jScrollPane();
        var height = $(window).height();
        //               $('.cho-ngoi').live('change',function(){
        //                   $(this).find('.seat-map').attr('ghe',$(this).val());
        //               alert($(this).val());
        //               });
        $('.seat-map[data-load-remote]').unbind('click').bind('click', function(e) {
            e.preventDefault();
            var val = [];
            $('.ticket-type').each(function(i) {
                val[i] = $(this).val();

            });
            // console.log(val);
            var $this = $(this);
            var cho_ngoi = $this.parent().find('.cho-ngoi').val();
            var remote = $this.data('load-remote');
            var img = '<div class="loading"><div style="width:134px;height:100px;margin:0 auto;padding-top: 60px;"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/frontend/images/ajaxloader.gif"></div></div>';
            $($this.data('remote-target')).html(img);
            $.ajax({
                url: remote,
                type: 'GET',
                data: {ticket_id: val},
                async: true,
                success: function(data) {
                    // console.log(val);
                    // $('.full-scroll').html(val);
                    // $($this.data('remote-target')).load(remote);
                    $('#Modalseatmap .modal-body').html(data);
                }
            });
        });
        setTimeout(function() {

            $('.nice-scroll').height($(window).height() - 100);
            $('.nice-full-scroll').height($(window).height() - 30);
<?php
if (!preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"])) {
    echo ' $(\'.nice-scroll\').jScrollPane();';
    echo ' $(\'.nice-full-scroll\').jScrollPane();';
}
?>
        }, 500);
    }
    ;
    function showmodal($this) {
        href = $this.attr('data-href');

        $(href).modal('show');
        var remote = $this.attr('data-load-remote');
        var img = '<div class="loading"><div style="width:134px;height:100px;margin:0 auto;padding-top: 60px;"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/frontend/images/ajaxloader.gif"></div></div>';

        $($this.attr('data-remote-target')).html(img);
        $.ajax({
            url: remote,
            type: 'GET',
            data: 'location=' + $(window)[0].location.href,
            cache: true,
            success: function(data) {
                $($this.attr('data-remote-target')).html(data);
            },
        });
        return false;
    }
    var $item_id;
<?php
if (isset($_GET['item_id'])) {
    ?>
        $item_id =<?php echo $_GET['item_id'] ?>;

    <?php
}
?>
    $(document).ready(function() {
        $(".user-dropdown").click(function() {
            $(".user-dropdown-menu").css("visibility", "visible");
            $(".user-dropdown-menu").css("height", "100px");
            $(".top-head ul li").css("z-index", "99999");
        });
        $(".user-dropdown-menu").mouseleave(function() {
            $(".user-dropdown-menu").css("visibility", "hidden");
            $(".top-head ul li").css("z-index", "0");
        });

        $baseUrl = window.location.href;
        // var flag = 0;
        $('html').bind('scroll', function(e) {
            if ($(this).hasClass('fancybox-lock')) {
                e.preventDefault();
            }
        });
        $event = 'click';
        $('#modal-details').on('hide.bs.modal', function() {
            $('html').removeClass('fancybox-lock');
            history.pushState('', 'wewe', $baseUrl);
            setTimeout(function() {
                if (!$('#modal-details:visible').length) {
                    $('#modal-details').find('.modal-body').html('');
                }
            }, 200);

        });
        $('#modal-details').on('shown.bs.modal', function() {
            $('html').addClass('fancybox-lock');

        });
        $('ul.menuman li a').each(function() {

            if ($(this).hasClass('submenu')) {

                if ($($(this))[0].href == String(window.location)) {

                    $(this).parent().parent().parent().addClass('active');
                }

            } else {

                if ($($(this))[0].href == String(window.location)) {

                    $(this).parent().addClass('active');
                    flag = 1;
                }
            }
        });
        jQuery(".select-lang").click(function() {
            jQuery('#form-lang').append('<input type="hidden" name="_lang" value="' + jQuery(this).attr('rel') + '" >');
            var date = $('#datepicker').val();
            jQuery('#form-lang').append('<input type="hidden" name="Event[date]" value="' + date + '" >');
            jQuery('#form-lang').submit();
            return false;
        });



    });
</script>
